home *** CD-ROM | disk | FTP | other *** search
/ CD Classic 39 / CD CLASSIC #39 (1998).iso / EMPRESA / visio / Vistdstd / Install / Data.Z / VGenericMFC.CPP < prev    next >
C/C++ Source or Header  |  1997-07-07  |  7KB  |  259 lines

  1. //*****************************************************************************
  2. //    VGENERICMFC.CPP - Generated by the "MFC VAddon VSL Wizard."
  3. //    Copyright (C) 1997 Visio Corporation. All rights reserved.
  4.  
  5. #include "stdafx.h"
  6.  
  7. #include "vGenericMFC.h"        //    Your wizard-generated subclass of VAddon
  8.  
  9.  
  10. //    The name that you give the VGenericMFC in its constructor
  11. //    is the text which shows up in the Visio Tools/Macros menu.
  12. //    _T(" - DEBUG") is automatically appended to the debug version
  13. //    for you by the VAddon class:
  14.  
  15. VGenericMFC g_vGenericMFCAddon(_T("GenericMFC"));
  16.  
  17.  
  18. //*****************************************************************************
  19.  
  20. //    Constructor and destructor:
  21.  
  22. VGenericMFC::VGenericMFC(LPCTSTR pName) : 
  23.     VAddon(ATTS, VAO_ENABLEALWAYS, 0, 0, pName)
  24. {
  25.  
  26. }
  27.  
  28. VGenericMFC::~VGenericMFC()
  29. {
  30.  
  31. }
  32.  
  33.  
  34. //*****************************************************************************
  35. //
  36. //    Handy little "error handling" macro...
  37. //    Requires a "CU:" (clean-up) label somewhere in the function
  38.  
  39. #define check_valid(hr, obj)                    \
  40.     if ( !SUCCEEDED(hr) || !((obj).IsSet()) )    \
  41.         goto CU;
  42.  
  43.  
  44. //*****************************************************************************
  45.  
  46. //    VAddon Overrides:
  47.  
  48. //    The Run method is pure virtual, with no implementation
  49. //    in the parent class. This method *MUST* be overridden,
  50. //    but it doesn't *HAVE* to do anything. (As you can see below,
  51. //    we're basically just returning VAORC_SUCCESS.)
  52.  
  53. //    The code in Run gets executed when the user chooses the
  54. //    Visio Tools menu item corresponding to your addon. It also
  55. //    gets executed when a shape sheet cell formula RUNADDON or
  56. //    RUNADDONWARGS gets evaluated.
  57.  
  58. VAORC VGenericMFC::Run(LPVAOV2LSTRUCT pV2L)
  59. {
  60.     BOOL bMadeIt= FALSE;
  61.     CVisioApplication app;
  62.  
  63.     if (SUCCEEDED(GetApp(app)))
  64.     {
  65.         //    Two non-wrapped event sinks which we must
  66.         //    'Release' manually:
  67.         IUnknown FAR        *pSink= NULL;
  68.         IUnknown FAR        *pAnotherSink= NULL;
  69.         HRESULT                hr= NOERROR;
  70.         static BOOL            bFirstTime= TRUE;    //    only add event callbacks once...
  71.  
  72.         //    The rest of these will be 'Release'd (if necessary) when
  73.         //    the function exits and they go out of scope:
  74.         CVisioEventList        eList;
  75.         CVisioEvent            event;
  76.         CVisioEvent            anotherEvent;
  77.         CVisioDocuments        docs;
  78.         CVisioDocument        doc;
  79.         CVisioPages            pages;
  80.         CVisioPage            page;
  81.         CVisioShape            shape;
  82.         CVisioShape            shape1;
  83.         CVisioMasters        masters;
  84.         CVisioMaster        master;
  85.         CVisioDocument        stencil;
  86.         CVisioCell            cell;
  87.         CVisioCell            cell1;
  88.  
  89.  
  90.         //    Add a 'Document Created' event notification and a 'Shape Added' notification
  91.         //    to the Application's EventList:
  92.  
  93. #if 0
  94.         if (bFirstTime && (SUCCEEDED(app.EventList(eList))))
  95.         {
  96.             bFirstTime= FALSE;
  97.  
  98.             if (SUCCEEDED(CoCreateAddonSink(ReceiveNotifyFromVisio, &pSink)))
  99.             {
  100.                 if (SUCCEEDED(eList.AddAdvise(visEvtCodeDocCreate, VVariant(pSink),
  101.                                                         VBstr(""), VBstr(""), event)))
  102.                 {
  103.                     event.ID(&stc_nEventID);
  104.                 }
  105.  
  106.                 pSink->Release();
  107.                 pSink= NULL;
  108.             }
  109.  
  110.             if (SUCCEEDED(CoCreateAddonSink(ReceiveAnotherNotifyFromVisio, &pAnotherSink)))
  111.             {
  112.                 if (SUCCEEDED(eList.AddAdvise((short)(visEvtShape|visEvtAdd), VVariant(pAnotherSink),
  113.                                                         VBstr(""), VBstr(""), anotherEvent)))
  114.                 {
  115.                     anotherEvent.ID(&stc_nAnotherEventID);
  116.                 }
  117.  
  118.                 pAnotherSink->Release();
  119.                 pAnotherSink= NULL;
  120.             }
  121.         }
  122. #endif
  123.  
  124.  
  125.         //    Add a new Document based on "sample.vst" and then drop two shapes
  126.         //    and glue them together...
  127.  
  128.         hr= app.Documents(docs);
  129.         check_valid(hr, docs);    
  130.  
  131.         hr= docs.Add(VBstr("sample.vst"), doc);
  132.         check_valid(hr, doc);
  133.  
  134.         hr= doc.Pages(pages);
  135.         check_valid(hr, pages);
  136.  
  137.         hr= pages.Item(VVariant(1L), page);
  138.         check_valid(hr, page);
  139.  
  140.         hr= docs.Item(VVariant("sample.vss"), stencil);
  141.         check_valid(hr, stencil);
  142.  
  143.         hr= stencil.Masters(masters);
  144.         check_valid(hr, masters);
  145.  
  146.         hr= masters.Item(VVariant("Executive"), master);
  147.         check_valid(hr, master);
  148.  
  149.         hr= page.Drop(master, 6.0, 6.0, shape);
  150.         check_valid(hr, shape);
  151.  
  152.         //    Re-using "master" without explicit 'Release' is OK --
  153.         //    wrapper classes take care of it for you
  154.         hr= masters.Item(VVariant("Position"), master);
  155.         check_valid(hr, master);
  156.  
  157.         hr= page.Drop(master, 3.0, 3.0, shape1);
  158.         check_valid(hr, shape1);
  159.  
  160.         hr= shape.Cells(VBstr("Connections.X4"), cell);
  161.         check_valid(hr, cell);
  162.  
  163.         hr= shape1.Cells(VBstr("Controls.X1"), cell1);
  164.         check_valid(hr, cell1);
  165.  
  166.            hr= cell1.GlueTo(cell);
  167.  
  168.         bMadeIt= TRUE;
  169.     }
  170.  
  171. CU:
  172.     if (!bMadeIt)
  173.     {
  174.         MessageBox(GetActiveWindow(), "Premature termination of GenericMFC. Is sample.vst/vss in the path?", "GenericMFC", MB_OK);
  175.     }
  176.  
  177.     return VAORC_SUCCESS;
  178. }
  179.  
  180.  
  181. //    The rest of the methods call the parent class,
  182. //    which performs default actions.
  183.  
  184. //    IsEnabled, Help and About are yours. The default
  185. //    actions in the parent class are: "Yes, I'm enabled"
  186. //    and a big fat no-op for Help and About.
  187.  
  188. VAORC VGenericMFC::IsEnabled(LPVAOV2LSTRUCT pV2L)
  189. {
  190.     return VAddon::IsEnabled(pV2L);
  191. }
  192.  
  193. VAORC VGenericMFC::About(LPVAOV2LSTRUCT pV2L)
  194. {
  195.     TCHAR szText[]= _T("GenericMFC Addon generated by MFC VAddon VSL Wizard.\n\nCopyright (c) 1997 by Visio Corporation.\nAll rights reserved.");
  196.     TCHAR szCaption[_MAX_PATH]= _T("About ");
  197.  
  198.     _tcscat(szCaption, GetName());
  199.     MessageBox(GetActiveWindow(), szText, szCaption, MB_OK);
  200.  
  201.     return VAORC_SUCCESS;
  202. }
  203.  
  204. VAORC VGenericMFC::Help(LPVAOV2LSTRUCT pV2L)
  205. {
  206.     TCHAR szText[]= _T("Code to jump to GenericMFC's help file is missing.");
  207.     TCHAR szCaption[_MAX_PATH]= _T("");
  208.  
  209.     _tcscpy(szCaption, GetName());
  210.     _tcscat(szCaption, _T(" Help"));
  211.     MessageBox(GetActiveWindow(), szText, szCaption, MB_OK);
  212.  
  213.     return VAORC_SUCCESS;
  214. }
  215.  
  216.  
  217. //    You should always call VAddon::Load, Unload and
  218. //    KillSession and GetInstance or do the things that they
  219. //    do in your methods. See the source in "vaddon.cpp"
  220. //    and "vao.c" for more details.
  221.  
  222. VAORC VGenericMFC::Load(WORD wVersion, LPVOID p)
  223. {
  224.     return VAddon::Load(wVersion, p);
  225. }
  226.  
  227. VAORC VGenericMFC::Unload(WORD wParam, LPVOID p)
  228. {
  229.     m_app= NULL;
  230.     return VAddon::Unload(wParam, p);
  231. }
  232.  
  233. VAORC VGenericMFC::KillSession(LPVAOV2LSTRUCT pV2L)
  234. {
  235.     return VAddon::KillSession(pV2L);
  236. }
  237.  
  238. HINSTANCE VGenericMFC::GetInstance(long nFlags /*= 0L*/)
  239. {
  240.     return VAddon::GetInstance(nFlags);
  241. }
  242.  
  243.  
  244. //*****************************************************************************
  245.  
  246. //    VGenericMFC convenience methods:
  247.  
  248. HRESULT VGenericMFC::GetApp(CVisioApplication &app)
  249. {
  250.     if (m_app.IsSet() || VAO_SUCCESS==vaoGetObjectWrap(m_app))
  251.     {
  252.         app= m_app;
  253.         return NOERROR;
  254.     }
  255.  
  256.     return E_FAIL;
  257. }
  258.  
  259.